package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.ExceptionLogMapper;
import com.itheima.pojo.ExceptionLog;
import com.itheima.service.ExceptionLogService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ExceptionLogServiceImpl implements ExceptionLogService {

    @Autowired
    private ExceptionLogMapper exceptionLogMapper;

    //获取系统异常列表
    @Override
    public Page<ExceptionLog> getExceptionList(ExceptionLog exceptionLog) {
        PageHelper.startPage(exceptionLog.getCurrentPage(),exceptionLog.getPageSize());

        String operation = exceptionLog.getOperation();
        if (operation.equals("")) {
            exceptionLog.setOperation(null);
        }

        List<ExceptionLog> logList=null;
        if (exceptionLog.getStartTime()!=null){
            String[] str = exceptionLog.getStartTime().split(",");

            Date date1 = DateUtils.str2Date(str[0]);
            String time1 = DateUtils.dateTimeToStr(date1);

            Date date2 = DateUtils.str2Date(str[1]);
            String time2 = DateUtils.dateTimeToStr(date2);

             logList = exceptionLogMapper.selectTime(time1,time2);
        }else {
            logList = exceptionLogMapper.select(exceptionLog);
        }
        return (Page<ExceptionLog>) logList;
    }
}
